from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

db_name = 'system_database'
# db_name = 'db_demo'
user_name = 'postgres'
password = 'Wtb20021207'

class DatabaseSessionSingleton:
    _instance = None

    def __new__(cls):
        if cls._instance is None:
            engine = create_engine(f'postgresql://{user_name}:{password}@localhost:5432/{db_name}', echo=False)
            cls._instance = sessionmaker(bind=engine)
        return cls._instance


# 创建一个获取数据库会话的函数
def get_db_session():
    return DatabaseSessionSingleton()
